package cn.gz.demo.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

import cn.gz.demo.AdapterRecyclerViewTablayoutBinding;
import cn.gz.demo.R;

/**
 * Created by Liuyz on 2017/11/13.
 */
public class RecyclerViewTablayoutListAdapter extends RecyclerView.Adapter<RecyclerViewTablayoutListAdapter.MyViewHolder> {
    private Activity context;
    private List<String> list;
    private List<String> cList = null;

    public RecyclerViewTablayoutListAdapter(Activity activity, List<String> response) {
        this.context = activity;
        this.list = response;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.recyclerview_tablayout_list_item, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        final String bean = list.get(position);
        holder.binding.name.setText(bean + "");
        if (position % 3 == 0) {
            holder.binding.layout.setBackgroundResource(R.color.pink);
        } else if (position % 3 == 1) {
            holder.binding.layout.setBackgroundResource(R.color.blue_dark);
        } else {
            holder.binding.layout.setBackgroundResource(R.color.background_color);
        }

        cList = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            cList.add("第" + position + "条第" + i + "项数据");
        }
        LinearLayoutManager layoutManager = new LinearLayoutManager(context) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        };
        holder.binding.recyclerview.setLayoutManager(layoutManager);
        holder.binding.recyclerview.setLayoutManager(new LinearLayoutManager(context));
        HomeAdapter adapter = new HomeAdapter(context, cList);
        holder.binding.recyclerview.setAdapter(adapter);
    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {
        AdapterRecyclerViewTablayoutBinding binding;

        public MyViewHolder(View view) {
            super(view);
            binding = DataBindingUtil.bind(view);
        }
    }
}
